import time

from appium import webdriver
from appium.options.common import AppiumOptions
from appium.webdriver.common.appiumby import AppiumBy

desired_caps = {
    'platformName': 'Android',  # 被测手机是安卓
    'platformVersion': '9',  # 手机安卓版本，如果是鸿蒙系统，依次尝试 12、11、10 这些版本号
    'deviceName': 'xxx',  # 设备名，安卓手机可以随意填写
    'appPackage': 'com.kkpodcast',  # 启动APP Package名称
    'appActivity': 'com.kkpodcast.activity.WelcomeActivity',  # 启动Activity名称
    'unicodeKeyboard': True,  # 自动化需要输入中文时填True
    'resetKeyboard': True,  # 执行完程序恢复原来输入法
    'noReset': True,  # 不要重置App
    'newCommandTimeout': 6000
}

# http://localhost:4723/wd/hub
# http://127.0.0.1:4723/wd/hub
url = "http://127.0.0.1:4723/wd/hub"

options = AppiumOptions()

options.set_capability('platformName', 'Android')
options.set_capability('platformVersion', '9')
options.set_capability('deviceName', 'xxx')
# options.set_capability('appPackage', 'com.kkpodcast')
# options.set_capability('appActivity', 'com.kkpodcast.activity.WelcomeActivity')
options.set_capability('noReset', True)
options.set_capability('browserName', 'Browser')
options.set_capability('chromedriverExecutable', r'D:\python-workspace\python-lizhe\python-common-trl\appAuto\chromedriver.exe')

driver = webdriver.Remote(url, options=options)
driver.get("https://www.baidu.com/")
# driver.find_element(AppiumBy.ACCESSIBILITY_ID, "库客音乐").click()

time.sleep(5)
print(driver.contexts)
# 输入手机号
# driver.find_element(AppiumBy.ID,"com.kkpodcast:id/input_phone_et").send_keys("19286685595")
# 输入密码
# driver.find_element(AppiumBy.ID, "com.kkpodcast:id/input_password_et").send_keys("123456789")
#
# time.sleep(2)
# 勾选同意协议
# driver.find_element(AppiumBy.CLASS_NAME, "android.widget.CheckBox").click()
#
# # 点击登录
# driver.find_element(AppiumBy.XPATH, '//*[@resource-id="com.kkpodcast:id/login_tv"]').click()

# 点击 发现 按钮
# driver.find_element(AppiumBy.ID, "com.kkpodcast:id/find_rb").click()
# time.sleep(2)
# 滑动页面
# driver.swipe(359, 1620, 476, 117)
# 点击歌单第一首歌
# driver.find_element(AppiumBy.XPATH, '//*[@resource-id="com.kkpodcast:id/song_sheet_rv"]/android.view.ViewGroup[1]').click()
